//
//  MyContactDemandCell.m
//  BusinessMarket
//
//  Created by Michael Li on 2018/12/10.
//  Copyright © 2018年 Michael Li. All rights reserved.
//

#import "MyContactDemandCell.h"
#import "HomeModel.h"
#import "RelationModel.h"
@interface MyContactDemandCell()
@property (weak, nonatomic) IBOutlet UIView *view;
@property (weak, nonatomic) IBOutlet UIImageView *iv;
@property (weak, nonatomic) IBOutlet UILabel *contentL;
@property (weak, nonatomic) IBOutlet UILabel *nickNamedAndIndustry;
@property (weak, nonatomic) IBOutlet UILabel *creatTimeL;
@property (weak, nonatomic) IBOutlet UIButton *contactBtn;
@property (weak, nonatomic) IBOutlet UIView *subView;
@property (weak, nonatomic) IBOutlet UIImageView *ivSub;
@property (weak, nonatomic) IBOutlet UILabel *nickNamedL;
@property (weak, nonatomic) IBOutlet UIButton *indicationBtn;
@property (weak, nonatomic) IBOutlet UIButton *phoneBtn;
@property (weak, nonatomic) IBOutlet UIButton *weiChatBtn;
@property (weak, nonatomic) IBOutlet UIButton *QQBtn;
@property(nonatomic,strong) UIButton *preBtn;
@property(nonatomic,strong) NSIndexPath *preIndexPath;
@property(nonatomic,strong) AFHTTPSessionManager *manager;
@property(nonatomic,strong) NSDictionary *dict;
@property(nonatomic,strong) CAShapeLayer *lineLayer;
@property (weak, nonatomic) IBOutlet UILabel *markL;
@property (weak, nonatomic) IBOutlet UIButton *reallyBtn;
@property (weak, nonatomic) IBOutlet UIButton *falseBtn;
@property (weak, nonatomic) IBOutlet UILabel *evaluateL;

@end
@implementation MyContactDemandCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.view.layer.masksToBounds = YES;
    self.view.layer.cornerRadius = 3;
    self.view.layer.borderColor = kLineColor.CGColor;
    self.view.layer.borderWidth = 1;
    self.subView.layer.masksToBounds = YES;
    self.subView.layer.cornerRadius = 3;
    self.subView.layer.borderColor = kLineColor.CGColor;
    self.subView.layer.borderWidth = 1;
    self.subView.hidden = YES;
    self.iv.layer.masksToBounds = YES;
    self.iv.layer.cornerRadius = 38/2;
    self.ivSub.layer.masksToBounds = YES;
    self.ivSub.layer.cornerRadius = 38/2;
    self.contactBtn.layer.masksToBounds = YES;
    self.contactBtn.layer.cornerRadius = 3;
    self.contactBtn.layer.borderColor = kLineColor.CGColor;
    self.contactBtn.layer.borderWidth = 1;
    [self.contactBtn setTitleColor:kLabel16Color forState:UIControlStateNormal];
    self.phoneBtn.layer.masksToBounds = YES;
    self.phoneBtn.layer.cornerRadius = 3;
    self.phoneBtn.layer.borderColor = kOrangeBg.CGColor;
    self.phoneBtn.layer.borderWidth = 1;
    self.weiChatBtn.layer.masksToBounds = YES;
    self.weiChatBtn.layer.cornerRadius = 3;
    self.weiChatBtn.layer.borderColor = [UIColor colorWithRed:226/255.0 green:237/255.0 blue:209/255.0 alpha:1].CGColor;
    self.weiChatBtn.layer.borderWidth = 1;
    self.weiChatBtn.layer.cornerRadius = 3;
    self.weiChatBtn.layer.borderColor = [UIColor colorWithRed:179/255.0 green:210/255.0 blue:135/255.0 alpha:1].CGColor;
    self.weiChatBtn.layer.borderWidth = 1;
    self.QQBtn.layer.masksToBounds = YES;
    self.QQBtn.layer.cornerRadius = 3;
    self.QQBtn.layer.borderColor = kLineColor.CGColor;
    self.QQBtn.layer.borderWidth = 1;
}
-(void)setModel:(HomeModel *)model
{
    _model = model;
    [self.lineLayer removeFromSuperlayer];
    //    homeModel.showView = homeModel.showView;
    if (model.show) {
        self.view.hidden = YES;
        self.subView.hidden = NO;
    }else {
        self.view.hidden = NO;
        self.subView.hidden = YES;
    }
    [self.iv sd_setImageWithURL:[NSURL URLWithString:model.headImg] placeholderImage:[UIImage imageNamed:@"headImg"]];
    self.nickNamedAndIndustry.text = [NSString stringWithFormat:@"%@%@",model.nicakName,model.industryList[0]];
    NSTimeInterval interval    = model.creattime/1000.0;
    NSDate *date               = [NSDate dateWithTimeIntervalSince1970:interval];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *currentDateStr = [formatter stringFromDate: date];
    self.creatTimeL.text = currentDateStr;
    self.contentL.text = model.represent;
    XLog(@"homeModel.represent:%@",model.represent);
    
    
    XLog(@"homemodel:%@",model.associationtypesubList);
    XLog(@"homeModel.associationtypesubList.count:%ld",model.associationtypesubList.count);
    [self.ivSub sd_setImageWithURL:[NSURL URLWithString:model.headImg] placeholderImage:[UIImage imageNamed:@"headImg"]];
    self.nickNamedL.text = model.nicakName;
    XLog(@"self.nickNamedL.text:%@",self.nickNamedL.text);
    [self.phoneBtn setTitle:[NSString stringWithFormat:@"电话:%@",model.phone] forState:UIControlStateNormal];
    [self.weiChatBtn setTitle:[NSString stringWithFormat:@"微信:%@",model.wechat] forState:UIControlStateNormal];
    [self.QQBtn setTitle:[NSString stringWithFormat:@"QQ:%@",model.qq] forState:UIControlStateNormal];
}
- (void)setRelationModel:(RelationModel *)relationModel
{
    _relationModel = relationModel;
    if (relationModel.show) {
        self.view.hidden = YES;
        self.subView.hidden = NO;
    }else {
        self.view.hidden = NO;
        self.subView.hidden = YES;
    }
    [self.iv sd_setImageWithURL:[NSURL URLWithString:relationModel.headImg] placeholderImage:[UIImage imageNamed:@"headImg"]];
    self.nickNamedAndIndustry.text = [NSString stringWithFormat:@"%@%@",relationModel.nicakName,relationModel.industryList[0]];
    NSTimeInterval interval    = relationModel.creattime/1000.0;
    NSDate *date               = [NSDate dateWithTimeIntervalSince1970:interval];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *currentDateStr = [formatter stringFromDate: date];
    self.creatTimeL.text = currentDateStr;
    self.contentL.text = [NSString stringWithFormat:@"需求概述:%@",relationModel.title];
    XLog(@"homeModel.represent:%@",relationModel.represent);
    
    
    XLog(@"homemodel:%@",relationModel.associationtypesubList);
    XLog(@"homeModel.associationtypesubList.count:%ld",relationModel.associationtypesubList.count);
    [self.ivSub sd_setImageWithURL:[NSURL URLWithString:relationModel.headImg] placeholderImage:[UIImage imageNamed:@"headImg"]];
    self.nickNamedL.text = relationModel.nicakName;
    XLog(@"self.nickNamedL.text:%@",self.nickNamedL.text);
    
    if (relationModel.phone.length == 0) {
        [self.phoneBtn setTitleColor:[UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1] forState:UIControlStateNormal];
        self.phoneBtn.layer.borderColor = [UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1].CGColor;
        [self.phoneBtn setTitle:[NSString stringWithFormat:@" 电话:该客户暂未填写"] forState:UIControlStateNormal];
    }else{
        [self.phoneBtn setTitle:[NSString stringWithFormat:@" 电话:%@",relationModel.phone] forState:UIControlStateNormal];
        self.phoneBtn.layer.borderColor = [UIColor colorWithRed:242/255.0 green:176/255.0 blue:81/255.0 alpha:1].CGColor;
    }
    
    if (relationModel.wechat.length == 0) {
        [self.weiChatBtn setTitleColor:[UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1] forState:UIControlStateNormal];
        self.weiChatBtn.layer.borderColor = [UIColor colorWithRed:224/255.0 green:224/255.0 blue:224/255.0 alpha:0.5].CGColor;
        [self.weiChatBtn setTitle:[NSString stringWithFormat:@" 微信:该客户暂未填写"] forState:UIControlStateNormal];
    }else{
        [self.weiChatBtn setTitle:[NSString stringWithFormat:@" 微信:%@",relationModel.wechat] forState:UIControlStateNormal];
        self.weiChatBtn.layer.borderColor = [UIColor colorWithRed:151/255.0 green:193/255.0 blue:91/255.0 alpha:1].CGColor;
    }
    
    if (relationModel.qq.length == 0) {
        [self.QQBtn setTitleColor:[UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1] forState:UIControlStateNormal];
        self.QQBtn.layer.borderColor = [UIColor colorWithRed:224/255.0 green:224/255.0 blue:224/255.0 alpha:0.5].CGColor;
        [self.QQBtn setTitle:[NSString stringWithFormat:@" QQ:该客户暂未填写"] forState:UIControlStateNormal];
    }else{
        [self.QQBtn setTitle:[NSString stringWithFormat:@" QQ:%@",relationModel.qq] forState:UIControlStateNormal];
        self.QQBtn.layer.borderColor = [UIColor colorWithRed:194/255.0 green:194/255.0 blue:194/255.0 alpha:1].CGColor;
        
    }
    
    
    if (relationModel.relationStatus == 0) {
        self.falseBtn.hidden = NO;
        self.reallyBtn.hidden = NO;
        self.markL.hidden =YES;
        self.evaluateL.text = @"待评价";
    }else if (relationModel.relationStatus == 1) {
        self.falseBtn.hidden = YES;
        self.reallyBtn.hidden = YES;
        self.evaluateL.text = @"已评价";
        self.markL.text = @"该需求为“真实需求”，推荐！";
        self.markL.hidden =NO;
        self.markL.textColor = [UIColor colorWithRed:141/255.0 green:183/255.0 blue:82/255.0 alpha:1];
    }else if (relationModel.relationStatus == 2) {
        self.falseBtn.hidden = YES;
        self.reallyBtn.hidden = YES;
        self.markL.hidden =NO;
        self.evaluateL.text = @"已评价";
        self.markL.text = @"该需求为“虚假需求”，不推荐！";
        self.markL.textColor = [UIColor colorWithRed:222/255.0 green:81/255.0 blue:72/255.0 alpha:1];
    }
    
}
- (void)setIndexPath:(NSIndexPath *)indexPath
{
    _indexPath = indexPath;
}
- (IBAction)contactBtn:(UIButton *)sender {
    
    sender.selected = YES;

//    self.indicationBtn.selected = NO;
    if ([self.delegate respondsToSelector:@selector(myContactDemandCell:withClickBtn:withIndexPath:withHomeModel:)]) {
        [self.delegate myContactDemandCell:self withClickBtn:sender withIndexPath:self.indexPath withHomeModel:self.relationModel];
    }

}
- (IBAction)indicatorBtn:(UIButton *)sender {
    
    sender.selected = NO;
    //    sender.selected = NO;
//    self.contactBtn.selected = NO;
    if ([self.delegate respondsToSelector:@selector(myContactDemandCell:withClickBtn:withIndexPath:withHomeModel:)]) {
        [self.delegate myContactDemandCell:self withClickBtn:sender withIndexPath:self.indexPath withHomeModel:self.relationModel];
    }
}
- (IBAction)reallyBtn:(UIButton *)sender {
    if ([self.delegate respondsToSelector:@selector(myContactDemandCell:withClickBtn:withIndexPath:)]) {
        [self.delegate myContactDemandCell:self withClickBtn:sender withIndexPath:self.indexPath];
    }
}
- (IBAction)falseBtn:(UIButton *)sender {
    if ([self.delegate respondsToSelector:@selector(myContactDemandCell:withClickBtn:withIndexPath:)]) {
        [self.delegate myContactDemandCell:self withClickBtn:sender withIndexPath:self.indexPath];
    }
}

@end
